#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>
#include <sstream>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <typeinfo>
using namespace std;

struct ListNode {
     int val;
     ListNode *next;
     ListNode() : val(0), next(nullptr) {}
     ListNode(int x) : val(x), next(nullptr) {}
     ListNode(int x, ListNode *next) : val(x), next(next) {}
};
//打印链表
void displayList(ListNode *p){
    while( p ){
        cout<< p->val ;
        p = p->next;
        if(p) cout<<"->";
    }
    cout<<endl;
}

//解决方案类
class Solution {
public:
    int lengthOfLastWord(string s) {
        int rt = 0,last = 0;
        for( auto i:s) rt = (i==' ')? (last=rt?rt:last),0 : rt+1;
        return rt?rt:last;
    }
};
int main(){
    Solution sp;
    string s = "aa f  ";
    vector<vector<int>> ans;
    cout<< sp.lengthOfLastWord(s);
    return 0;
}